<?php
session_start();
include "../../include/dbFunctions.php";
$cid = $_POST['cid'];
$vid = $_POST['vid'];
$eid = $_SESSION['eid'];
$query1 = "UPDATE trainer
            SET trainer_status = 'confirmed',
                class_id = $cid
            WHERE event_id = $eid
            AND volunteer_id = $vid";
$result1 = executeQuery($query1);
//trainer
/*
$query2= "SELECT volunteer_id FROM trainer WHERE event_id = $eid AND trainer_status = 'confirmed'";
$trainer_array = executeSelectQuery($query2);
$query3= "SELECT class_id FROM class WHERE event_id = $vid ";
$class = executeSelectQuery($query3);
$no_ready = count($trainer_array);
$trainer_required = count($class)*2;
if ($no_ready==$trainer_required) {
    $query = "UPDATE event
            SET event_status = 'confirmed'
            WHERE event_id = $eid";
    $result = executeQuery($query);
}
*/
if ($result1!=0) {
    $_SESSION['mes']="The record has been updated successfully";
    header('Location: ' . $_SERVER['HTTP_REFERER']);
} else {
    $_SESSION['mes']="Error! Please try again";
    header('Location: ' . $_SERVER['HTTP_REFERER']);
}
?>
